var mapIds = [993000100];
var 准备地图 = 993000600;

function init() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance("活动_守卫城墙");
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        d.resetFully();
        d.killAllMonsters(false)
    }
    return c
}

function onPlayerRegistered(b, a) {
    a.setReviveCount(-100);
    var c = b.getMapInstance(0);
    a.changeMap(c, c.getPortal(0));
    b.startEventTimer(3 * 60 * 1000)
}

function onPlayerRevived(b, a) {
    return false
}

function onMapChanged(c, b, a) {
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
    em.setProperty("kill", "0");
    em.setProperty("clear", "0");
    em.setProperty("curMap", a)
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onMonsterDamaged(b, a, d, e, c) {}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onMonsterKilled(b, c) {
    var a = em.getNumberProperty("kill") + 1;
    em.setProperty("kill", a);
    if (a == 29) {
        player.getAPI().playerMessage(-1, "抵挡住了攻击。请准备进行下一回合。");
        player.getAPI().fieldEffect_ScreenMsg("defense/count");
        var d = 29 * Math.pow(player.getAPI().getLevel(), 2) * Math.pow(2, 1);
        player.getAPI().gainExp(d);
        player.getAPI().effect_GainExpGold(d);
        b.schedule("mob2", 3 * 1000)
    } else {
        if (a == 58) {
            player.getAPI().playerMessage(-1, "抵挡住了攻击。请准备进行下一回合。");
            var d = 58 * Math.pow(player.getAPI().getLevel(), 2) * Math.pow(2, 1.25);
            player.getAPI().gainExp(d);
            player.getAPI().effect_GainExpGold(d);
            player.getAPI().fieldEffect_ScreenMsg("defense/count");
            b.schedule("mob3", 3 * 1000)
        } else {
            if (a == 68) {
                player.getAPI().fieldEffect_ScreenMsg("killing/clear");
                var d = 68 * Math.pow(player.getAPI().getLevel(), 2) * Math.pow(2, 1.5);
                player.getAPI().gainExp(d);
                player.getAPI().effect_GainExpGold(d);
                player.scheduleWarpTask(3, 993000600, 0, false);
                player.getAPI().protectWallWave(4);
                player.getAPI().setQuestCustomData(9930001, 4)
            }
        }
    }
    return 1
}

function mob1(a) {
    a.getPlayers().forEach(function (b) {
        b.getAPI().protectWallWave(1);
        b.getAPI().setQuestCustomData(9930001, 1);
        b.getAPI().fieldEffect_ScreenMsg("defense/wave/1");
        b.getAPI().fieldEffect_ScreenMsg("killing/first/start");
        b.getAPI().spawnMobSchedule(9831000, 1, 500, 165, 3000);
        b.getAPI().spawnMobSchedule(9831000, 1, 500, 165, 3500);
        b.getAPI().spawnMobSchedule(9831000, 1, 500, 165, 4000);
        b.getAPI().spawnMobSchedule(9831000, 1, 500, 165, 4500);
        b.getAPI().spawnMobSchedule(9831001, 1, 500, 165, 5000);
        b.getAPI().spawnMobSchedule(9831001, 1, 500, -195, 6000);
        b.getAPI().spawnMobSchedule(9831000, 1, 500, 165, 6500);
        b.getAPI().spawnMobSchedule(9831001, 1, 500, 165, 7000);
        b.getAPI().spawnMobSchedule(9831000, 1, 500, 165, 7500);
        b.getAPI().spawnMobSchedule(9831000, 1, 500, 165, 8000);
        b.getAPI().spawnMobSchedule(9831000, 1, 500, 165, 8500);
        b.getAPI().spawnMobSchedule(9831001, 1, 500, 165, 9000);
        b.getAPI().spawnMobSchedule(9831001, 1, 500, -195, 5000);
        b.getAPI().spawnMobSchedule(9831000, 1, 500, 165, 10000);
        b.getAPI().spawnMobSchedule(9831000, 1, 500, 165, 10500);
        b.getAPI().spawnMobSchedule(9831000, 1, 500, 165, 12000);
        b.getAPI().spawnMobSchedule(9831000, 1, 500, 165, 12500);
        b.getAPI().spawnMobSchedule(9831000, 1, 500, 165, 13000);
        b.getAPI().spawnMobSchedule(9831001, 1, 500, 165, 13500);
        b.getAPI().spawnMobSchedule(9831001, 1, 500, -195, 14000);
        b.getAPI().spawnMobSchedule(9831000, 1, 500, 165, 15000);
        b.getAPI().spawnMobSchedule(9831002, 1, 500, -195, 15500);
        b.getAPI().spawnMobSchedule(9831000, 1, 500, 165, 16000);
        b.getAPI().spawnMobSchedule(9831001, 1, 500, -195, 16500);
        b.getAPI().spawnMobSchedule(9831001, 1, 500, 165, 18000);
        b.getAPI().spawnMobSchedule(9831001, 1, 500, -195, 18500);
        b.getAPI().spawnMobSchedule(9831001, 1, 500, 165, 19000);
        b.getAPI().spawnMobSchedule(9831001, 1, 500, -195, 15000);
        b.getAPI().spawnMobSchedule(9831001, 1, 500, 165, 20000)
    })
}

function mob2(a) {
    a.getPlayers().forEach(function (b) {
        b.getAPI().protectWallWave(2);
        b.getAPI().setQuestCustomData(9930001, 2);
        b.getAPI().fieldEffect_ScreenMsg("defense/wave/2");
        b.getAPI().fieldEffect_ScreenMsg("killing/first/start");
        b.getAPI().spawnMobSchedule(9831006, 1, 500, 165, 3000);
        b.getAPI().spawnMobSchedule(9831006, 1, 500, 165, 3500);
        b.getAPI().spawnMobSchedule(9831006, 1, 500, 165, 4000);
        b.getAPI().spawnMobSchedule(9831006, 1, 500, 165, 4500);
        b.getAPI().spawnMobSchedule(9831007, 1, 500, 165, 5000);
        b.getAPI().spawnMobSchedule(9831007, 1, 500, -195, 5500);
        b.getAPI().spawnMobSchedule(9831006, 1, 500, 165, 6000);
        b.getAPI().spawnMobSchedule(9831007, 1, 500, 165, 6500);
        b.getAPI().spawnMobSchedule(9831006, 1, 500, 165, 7000);
        b.getAPI().spawnMobSchedule(9831006, 1, 500, 165, 7500);
        b.getAPI().spawnMobSchedule(9831006, 1, 500, 165, 8000);
        b.getAPI().spawnMobSchedule(9831007, 1, 500, 165, 8500);
        b.getAPI().spawnMobSchedule(9831007, 1, 500, -195, 9000);
        b.getAPI().spawnMobSchedule(9831006, 1, 500, 165, 5000);
        b.getAPI().spawnMobSchedule(9831006, 1, 500, 165, 10000);
        b.getAPI().spawnMobSchedule(9831006, 1, 500, 165, 10500);
        b.getAPI().spawnMobSchedule(9831006, 1, 500, 165, 11000);
        b.getAPI().spawnMobSchedule(9831006, 1, 500, 165, 11500);
        b.getAPI().spawnMobSchedule(9831007, 1, 500, 165, 12000);
        b.getAPI().spawnMobSchedule(9831007, 1, 500, -195, 12500);
        b.getAPI().spawnMobSchedule(9831006, 1, 500, 165, 13000);
        b.getAPI().spawnMobSchedule(9831008, 1, 500, -195, 14500);
        b.getAPI().spawnMobSchedule(9831006, 1, 500, 165, 15000);
        b.getAPI().spawnMobSchedule(9831007, 1, 500, -195, 15500);
        b.getAPI().spawnMobSchedule(9831007, 1, 500, 165, 16000);
        b.getAPI().spawnMobSchedule(9831007, 1, 500, -195, 16500);
        b.getAPI().spawnMobSchedule(9831007, 1, 500, 165, 17000);
        b.getAPI().spawnMobSchedule(9831007, 1, 500, -195, 17500);
        b.getAPI().spawnMobSchedule(9831007, 1, 500, 165, 18000)
    })
}

function mob3(a) {
    a.getPlayers().forEach(function (b) {
        b.getAPI().protectWallWave(3);
        b.getAPI().setQuestCustomData(9930001, 3);
        b.getAPI().fieldEffect_ScreenMsg("defense/wave/3");
        b.getAPI().fieldEffect_ScreenMsg("killing/first/start");
        b.getAPI().spawnMobSchedule(9831013, 1, 500, 165, 3000);
        b.getAPI().spawnMobSchedule(9831013, 1, 500, -195, 3500);
        b.getAPI().spawnMobSchedule(9831013, 1, 500, 165, 4000);
        b.getAPI().spawnMobSchedule(9831013, 1, 500, -195, 4500);
        b.getAPI().spawnMobSchedule(9831013, 1, 500, 165, 5000);
        b.getAPI().spawnMobSchedule(9831013, 1, 500, -195, 5500);
        b.getAPI().spawnMobSchedule(9831013, 1, 500, 165, 6000);
        b.getAPI().spawnMobSchedule(9831013, 1, 500, -195, 6500);
        b.getAPI().spawnMobSchedule(9831014, 1, 500, 165, 7000);
        b.getAPI().spawnMobSchedule(9831014, 1, 500, -195, 7500)
    })
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}
var setupTask;

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    if (b.getQuestStatus(16406) == 1) {
        b.getAPI().addNumberForQuestInfo(16406, "count", 1)
    }
    if (b.getQuestStatus(16407) == 1) {
        b.getAPI().addNumberForQuestInfo(16407, "count", 1)
    }
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onItemPickedUp(b, a, c) {};